package com.study.d10_period_duration;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;

public class Test {
    public static void main(String[] args) {
        //掌握Period的作用：计算两个日期对于维度数据相差的年数，月数，天数
        LocalDate localDate = LocalDate.of(2050, 10, 1);
        LocalDate localDate2 = LocalDate.of(1921, 7, 1);
        Period between = Period.between(localDate2, localDate);
        System.out.println(between.getYears());
        System.out.println(between.getMonths());
        System.out.println(between.getDays());

        //Duration（持续时间）：可以计算两个时间对象相差的天数、小时数、分数、秒数、纳秒数，支持LocalDate LocalDateTime、Instant等时间
        LocalDateTime ldt1 = LocalDateTime.of(1921, 7, 1, 10, 05, 15);
        LocalDateTime ldt2 = LocalDateTime.of(2050, 10, 1, 11, 12, 13);
        Duration between2 = Duration.between(ldt1, ldt2);
        System.out.println(between2.toDays());
        System.out.println(between2.toHours());
        System.out.println(between2.toMinutes());
        System.out.println(between2.toMillis());
        System.out.println(between2.toNanos());
    }
}
